import {reqDetail,reqAddCart} from '@/api/'
import {getuuId} from '@/utils/'
export default {
    state: () => ({
        details:{},
        uuId:getuuId()
    }),
    getters:{
        skuInfo(state){
            return state.details.skuInfo
        },
        spuSaleAttrList(state){
            return state.details.spuSaleAttrList
        }
    },
    mutations:{
        GETDETIAL(state,data){
            state.details=data
        }
    },
    actions: {
        async getDetail(context,skuid){
           try{
                const detail= await reqDetail(skuid)
                if(detail.code===200){
                    context.commit("GETDETIAL",detail.data)
                }
           }catch(error){

           }
             
        },
        async addCart(context,data){
            try{
                const s =  await reqAddCart(data.skuId,data.skuNum)
                if(s.code===200){
                    return  'ok'
                }else{
                    return Promise.reject(new Error("faile"));
                }
            }catch(error){
                return Promise.reject(new Error("请求失败"));
            }
        }
    }
}